home *** CD-ROM | disk | FTP | other *** search
/ Aminet 13 / Aminet 13 - August 1996.iso / Aminet / comm / fido / MM_AStat10_GG.lha / MM / Rexx / MM_AreaStat.rexx
OS/2 REXX Batch file  |  1995-09-09  |  13KB  |  672 lines

  1. /*
  2. ** MM_AreaStat.rexx by Gabriele Greco
  3. **
  4. ** based on AreaStat.ems by Adam Sjøgren & Bernd Ernesti
  5. ** Inspired by AreaStat.spot by Brian Jacobsen.
  6. **
  7. ** Insert in your MailManager config file the following line:
  8. **
  9. ** #BROWSEMENU    "Statistics"    "rx MM:rexx/mm_Areastat.rexx %a" "S"
  10. **
  11. */
  12. /****************************************/
  13. /* $VER: MM_AreaStat.rexx 1.0 (25.5.95) */
  14. /****************************************/
  15.  
  16. options results
  17. signal on error
  18. signal on syntax
  19.  
  20. parse arg current_area .
  21.  
  22. address MAILMANAGER
  23.  
  24. /* Variables: */
  25.  
  26. drop names.
  27. drop fromlist.
  28. drop tolist.
  29. drop subjlist.
  30. drop chars.
  31. drop quoting.
  32. drop subjs.
  33. drop chars_out.
  34. drop quoting_out.
  35. drop from_out.
  36. drop MM.
  37. drop to_out.
  38. drop subj_pit.
  39. drop resp.
  40.  
  41. fromlist. = 0
  42. tolist.   = 0
  43. subjlist. = 0
  44. names.COUNT  = 0
  45. subjs.COUNT  = 0
  46. quoting.COUNT = 0
  47. chars.COUNT = 0
  48. to_out.COUNT = 0
  49. from_out.COUNT = 0
  50. subj_out.COUNT = 0
  51. chars_out.COUNT = 0
  52. quoting_out.COUNT = 0
  53.  
  54. m.JAN =1
  55. m.FEB =2
  56. m.MAR = 3
  57. m.APR = 4
  58. m.MAY = 5
  59. m.JUN = 6
  60. m.JUL = 7 
  61. m.AUG = 8
  62. m.SEP = 9
  63. m.OCT = 10
  64. m.NOV = 11
  65. m.DIC = 12
  66.  
  67. MM.PrgName = 'MM_AreaStat v1.00'
  68. MM.Copyright = '(c) 1995 Gabriele Greco'
  69. MM.LogLevel = 2
  70.  
  71. msgarea = current_area 
  72.  
  73. MM_GetAreaInfo current_area area
  74.  
  75. if area.NMSG = 0 then
  76. do
  77.  
  78.    call Requester(MM.PrgName, 'The area 'area.NAME' is empty.', 'I knew that!' )
  79.    signal ScriptEnd
  80.  
  81. end
  82.  
  83. StartMsg = area.HIMSG - area.NMSG
  84. EndMsg   = area.HIMSG
  85.  
  86. /* A full Messagebase, or just the last month? */
  87. res.COUNT = 4
  88. res.0 = 'Full Messagebase'
  89. res.1 = 'By the Real-Message-Number'
  90. res.2 = 'By month and year'
  91. res.3 = 'By the year'
  92.  
  93. sel.   = 0
  94.  
  95. MM_SingleSelReq res sel '"How long search for ?"' NUM
  96.  
  97. if RC = 1 then signal ScriptEnd
  98.  
  99. smb   = 1
  100. month = ''
  101. year  = ''
  102.  
  103. if sel.0 = 0 then month='#?'
  104.  
  105. if sel.0 = 1 then
  106. do
  107.  
  108.    MM_StringReq '"Start Msg-Number ?"' 'StartMsg'
  109.    if StartMsg > area.HIMSG | StartMsg < (area.HIMSG - area.NMSG) then signal ScriptEnd
  110.    MM_StringReq '"End Msg-Number ?"'  'EndMsg'
  111.    if EndMsg   > area.HIMSG | EndMsg < StartMsg then signal ScriptEnd
  112.    smb = 2
  113.  
  114. end
  115.  
  116. if sel.0 = 2 then
  117. do
  118.  
  119.    MM_StringReq '"Which Month (3 chars, e.g. JAN) ?"' 'month'
  120.  
  121.    month = left( compress( upper( month ) ), 3 )
  122.  
  123.    test = pos( month, 'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC' )
  124.  
  125.    if test ~= 0 & (test=1 | (test - 1)//3 = 0) then smb   = 3
  126.                                                else month = '#?'
  127. end
  128.  
  129. if sel.0 = 2 | sel.0 = 3 then
  130. do
  131.  
  132.    MM_StringReq '"Which Year ?"' 'year'
  133.  
  134.    year = COMPRESS( year ); if year = '' | length( Year ) < 2 | DATATYPE( year ) ~= 'NUM' then
  135.    do
  136.  
  137.       month = '#?'
  138.       year  = '#?'
  139.       smb   = 1
  140.  
  141.    end
  142.    else
  143.    do
  144.  
  145.       year = right( year, 2 )
  146.  
  147.       if smb ~= 3 then
  148.       do
  149.          smb   = 4
  150.          month = ''
  151.       end
  152.  
  153.    end
  154.  
  155. end
  156.  
  157. /* A full stat's file, or just the first 10? */
  158. res.COUNT = 2
  159. res.0 = 'Top 10 only'
  160. res.1 = 'Full statistics'
  161. sel.0   = 0
  162. MM_SingleSelReq res sel '"What kind of statistics?"' NUM
  163.  
  164. if RC = 1 then signal ScriptEnd
  165.  
  166. if sel.0 = 0 then
  167. do
  168.  
  169.    toptext = 'Top Ten'
  170.    top     = 1
  171.  
  172. end
  173. else
  174. do
  175.  
  176.    toptext = 'All'
  177.    top     = 0
  178.  
  179. end
  180.  
  181. /* How do you want the output? */
  182. output_area = ''
  183. output_file = ''
  184. res.COUNT=2
  185. res.0 = 'Send as a message'
  186. res.1 = 'To a file'
  187. sel.0   = 0
  188. MM_SingleSelReq res sel '"Where do you want the chart?"' NUM
  189. if RC=1 then signal ScriptEnd
  190.  
  191. StartMsg = StartMsg + 1
  192.  
  193. if sel.0=0 then
  194. do
  195.    res.COUNT = 2
  196.    res.0 = 'Current Area'
  197.    res.1 = 'Choose from list'
  198.    sel2.  = 0
  199.    MM_SingleSelReq res sel2 '"Post in what area?"' NUM
  200.    if RC = 1 then signal ScriptEnd
  201.  
  202.    if sel2.0 = 0 then
  203.    do
  204.  
  205.       output_area = current_area
  206.  
  207.    end
  208.    else
  209.    do
  210.  
  211.      output_area = ''
  212.      MM_AreaReq 'output_area'
  213.      if RC = 1 then signal ScriptEnd
  214.  
  215.    end
  216.  
  217. end
  218. else
  219. do
  220.  
  221.    output_file = ''
  222.    MM_FileReq 'output_file'
  223.    if RC = 1 then signal ScriptEnd
  224. end
  225.  
  226. TotalMsg = 0
  227.  
  228. firstchars = xrange('00'x,'1f'x)
  229. lastchars = xrange('80'x,'ff'x)
  230.  
  231. do i = StartMsg to EndMsg
  232.  
  233.    say 'Examining' i
  234.  
  235.    MM_ReadMsg msgarea i msg
  236.  
  237.    date_ = msg.DATE
  238.    to_ = msg.TO
  239.    from_ = msg.FROM
  240.    subj_ = msg.SUBJ
  241.  
  242.    subj_ = upper( strip( subj_ ) )
  243.  
  244.    if i = StartMsg then StartMsgDate = date_
  245.    if i = EndMsg   then EndMsgDate   = date_
  246.  
  247.    test = pos( month || year, compress( upper( date_ ) ) )
  248.  
  249.    if test = 0 & smb > 2 then iterate
  250.    if smb  = 4 & (test ~= 9 & test ~= 6) then iterate
  251.  
  252.    if left( subj_, 4 ) = 'RE: ' then subj_ = substr( subj_, 5 )
  253.  
  254.    quotes=0
  255.    offpolicy=0
  256.  
  257.    do j=0 to msg.TEXT.COUNT-1
  258.     if pos('>', msg.TEXT.j )>0 then quotes=quotes+1
  259.     else do
  260.         if verify(msg.TEXT.j,lastchars,'m')>0 then offpolicy=1
  261.         if verify(msg.TEXT.j,firstchars,'m')>0 then offpolicy=1
  262.     end
  263.    end
  264.  
  265.    if quotes>0 then quotes=quotes*100/msg.TEXT.COUNT
  266.  
  267.    subj_=compress(subj_,"#*')")
  268.    subj_=compress(subj_,':"?(')
  269.    from_=compress(from_,"*'")
  270.    to_=compress(to_,"*'")
  271.  
  272.    MM_SearchInStem names Resp '"'from_'"' NUM
  273.  
  274.    if Resp.COUNT = 0 then do
  275.     chars.from_ = 0
  276.     quoting.from_=0
  277.     MM_AddToStem 'names' 'from_'
  278.    end
  279.  
  280.    MM_SearchInStem names Resp '"'to_'"' NUM
  281.  
  282.    if Resp.COUNT = 0 then do
  283.     chars.to_ = 0
  284.     quoting.to_=0
  285.     MM_AddToStem 'names' 'to_'
  286.    end
  287.  
  288.    MM_SearchInStem subjs Resp '"'subj_'"' NUM
  289.  
  290.    if Resp.COUNT = 0 then do
  291.     MM_AddToStem 'subjs' 'subj_'
  292.    end
  293.  
  294.    if (fromlist.from_>0) then quoting.from_ = (quoting.from_*fromlist.from_+quotes)/(fromlist.from_+1)
  295.        else quoting.from_ = quotes
  296.  
  297.    say 'from:' from_ 'quoting:' quotes||'% offpolicy:' offpolicy 'subj:' subj_
  298.  
  299.    if offpolicy=1 then chars.from_ = chars.from_ + 1
  300.    tolist.to_     = tolist.to_     + 1
  301.    fromlist.from_ = fromlist.from_ + 1
  302.    subjlist.subj_ = subjlist.subj_ + 1
  303.    TotalMsg      = TotalMsg      + 1
  304.  
  305. end
  306.  
  307. if month="#?" then do
  308.   say StartMsgDate
  309.   parse var StartMsgDate giorno ' ' mese ' ' anno '  '
  310.   mese = UPPER(mese)
  311.   ms = copies( '0', 2-length(m.mese))||m.mese
  312.   a='19'||anno||ms||giorno
  313.  
  314.   say a
  315.   sd = date('I',a,'S')
  316.  
  317.   say EndMsgDate
  318.  
  319.   parse var EndMsgDate giorno ' ' mese ' ' anno '  '
  320.   mese = UPPER(mese)
  321.   ms = copies( '0', 2-length(m.mese))||m.mese
  322.   a='19'||anno||ms||giorno
  323.  
  324.   say a
  325.  
  326.   ed = date('I',a,'S')
  327.  
  328.   days = ed - sd
  329. end
  330. else days=30
  331.  
  332. messgiorno = TotalMsg / days
  333.  
  334. messgiorno = messgiorno % 1
  335.  
  336. do i=0 to names.COUNT-1
  337.     say names.i
  338. end
  339.  
  340. do i=0 to subjs.COUNT-1
  341.     say subjs.i
  342. end
  343.  
  344. if TotalMsg = 0 then
  345. do
  346.    call Requester(MM.PrgName, 'No messages found !', 'Bye!')
  347.    signal ScriptEnd
  348. end
  349.  
  350. /* Make the TO: stem ready */
  351.  
  352. do i = 0 to names.COUNT-1
  353.  
  354.    aname = names.i
  355.  
  356.    if tolist.aname > 0 then
  357.    do
  358.  
  359.       percent   = tolist.aname * 100 / TotalMsg
  360.       remainder = percent // 1
  361.       percent   = percent  % 1
  362.  
  363.       if remainder > 0.5 then percent = percent + 1
  364.  
  365.       out_1 =            copies( ' ', (length( names.COUNT ) + 1) - length( tolist.aname ) ) || tolist.aname
  366.       out_2 = 'msgs(' || copies( ' ', 3  - length( percent ) ) || percent || '%) to' aname
  367.  
  368.  
  369.       out=out_1||' '||out_2
  370.  
  371.       MM_AddToStem  to_out 'out'
  372.  
  373.    end
  374.  
  375. end
  376.  
  377. MM_SortStem to_out
  378.  
  379. /* Make the offpolicy chars stem ready */
  380.  
  381. do i = 0 to names.COUNT-1
  382.  
  383.    aname = names.i
  384.  
  385.    if chars.aname > 0 then
  386.    do
  387.       out_1 = copies( ' ', (length( names.COUNT ) + 1) - length( chars.aname ) ) || chars.aname
  388.       out_2 = 'msgs with off-policy characters by' aname
  389.  
  390.       out=out_1||' '||out_2
  391.  
  392.       MM_AddToStem  chars_out 'out'
  393.  
  394.    end
  395.  
  396. end
  397.  
  398. MM_SortStem chars_out
  399.  
  400.  
  401. /* The FROM: stem: */
  402. do i = 0 to names.COUNT-1
  403.  
  404.    aname = names.i
  405.  
  406.    if fromlist.aname > 0 then
  407.    do
  408.  
  409.       percent   = fromlist.aname * 100 / TotalMsg
  410.       remainder = percent // 1
  411.       percent   = percent  % 1
  412.  
  413.       if remainder > 0.5 then percent = percent + 1
  414.  
  415.       out_1 =            copies( ' ', (length( names.COUNT ) + 1) - length( fromlist.aname ) ) || fromlist.aname
  416.       out_2 = 'msgs(' || copies( ' ',                      3  - length( percent     ) ) || percent || '%) from' names.i
  417.  
  418.       out=out_1||' '|| out_2
  419.  
  420.       MM_AddToStem from_out 'out'
  421.  
  422.    end
  423.  
  424. end
  425.  
  426. MM_SortStem from_out
  427.  
  428. /* The quoting stem: */
  429.  
  430. do i = 0 to names.COUNT-1
  431.  
  432.    aname = names.i
  433.  
  434.    if quoting.aname > 0 then
  435.    do
  436.       remainder = quoting.aname // 1
  437.       percent   = quoting.aname  % 1
  438.  
  439.       if remainder > 0.5 then percent = percent + 1
  440.  
  441.       out = copies( ' ',                      3  - length( percent     ) ) || percent || '% of quoting ('||copies( ' ',(length( names.COUNT ) + 1) - length( fromlist.aname )) || fromlist.aname || ' msgs) by' names.i
  442.  
  443.       MM_AddToStem quoting_out 'out'
  444.  
  445.    end
  446.  
  447. end
  448.  
  449. MM_SortStem quoting_out
  450.  
  451.  
  452. /* The SUBJ: stem: */
  453. do i = 0 to subjs.COUNT-1
  454.  
  455.    subj_ = subjs.i
  456.  
  457.    if subjlist.subj_ > 0 then
  458.    do
  459.  
  460.       percent   = subjlist.subj_ * 100 / TotalMsg
  461.       remainder = percent // 1
  462.       percent   = percent  % 1
  463.  
  464.       if remainder > 0.5 then percent = percent + 1
  465.  
  466.       out_1 =              copies( ' ', (length( subjs.COUNT ) + 1) - length( subjlist.subj_ ) ) || subjlist.subj_
  467.       out_2 = 'topics(' || copies( ' ',                     3  - length( percent     ) ) || percent || '%) :' subjs.i
  468.  
  469.       out=out_1||' '||out_2
  470.  
  471.       MM_AddToStem subj_out 'out'
  472.  
  473.    end
  474.  
  475. end
  476.  
  477. MM_SortStem subj_out
  478.  
  479.  
  480. /* Do the output: */
  481. temp_file = 't:MM_areastat'
  482. mline = '----------------------------------------------------------------------------'
  483.  
  484. call open( 'temp', temp_file, 'W' )
  485.  
  486. call writeln( 'temp', ''                            )
  487. call writeln( 'temp', 'Area-Statistics for' msgarea )
  488. call writeln( 'temp', 'Generated with the MailManager Statistic Generator')
  489. call writeln( 'temp', 'written by Gabriele Greco')
  490. call writeln( 'temp', mline )
  491. if smb = 1 then call writeln( 'temp', 'Full Messagebase with' TotalMsg 'messages')
  492. if smb = 2 then call writeln( 'temp', 'Msg #' || StartMsg '(' || StartMsgDate || ')' '-' '#' || EndMsg '(' || EndMsgDate || ')' 'with' TotalMsg 'msgs')
  493. if smb > 2 then
  494. do
  495.  
  496.    if smb = 3 then part = 'Month' month
  497.               else part = 'Year'
  498.  
  499.    if year > 77 then part = part '19' || year
  500.                 else part = part '20' || year
  501.  
  502.    call writeln( 'temp', 'Messagebase from' part 'with' TotalMsg 'messages' )
  503.  
  504. end
  505.  
  506. call writeln( 'temp', 'Statistics generated on  :' DATE() 'at' TIME() )
  507. call writeln( 'temp', 'Active users in this area:' names.COUNT        )
  508. call writeln( 'temp', 'Average messages/day     :' messgiorno  )
  509. call writeln( 'temp', mline                                           )
  510. call writeln( 'temp', ''                                              )
  511.  
  512. if top = 1 then
  513. do
  514.  
  515.    low_f = (from_out.COUNT) - 10; j_f = 10
  516.    low_t = (  to_out.COUNT) - 10; j_t = 10
  517.    low_s = (subj_out.COUNT) - 10; j_s = 10
  518.    j_q = 10
  519.  
  520.    if quoting_out.COUNT>10 then low_q = (quoting_out.COUNT) - 10
  521.    else do
  522.     low_q=0
  523.     j_q=quoting_out.COUNT
  524.    end
  525.  
  526.    j_o=10
  527.  
  528.    if chars_out.COUNT>10 then low_o = (chars_out.COUNT) - 10
  529.    else do
  530.     low_o=0
  531.     j_o= chars_out.COUNT
  532.    end
  533. end
  534. else
  535. do
  536.  
  537.    low_f = 0; j_f   = from_out.COUNT
  538.    low_t = 0; j_t   =   to_out.COUNT
  539.    low_s = 0; j_s   = subj_out.COUNT
  540.    low_q = 0; j_q   = quoting_out.COUNT
  541.    low_o = 0; j_o   = quoting_out.COUNT
  542. end
  543.  
  544. j = 0
  545. call writeln( 'temp', toptext 'Submitters:' )
  546. call writeln( 'temp', mline                 )
  547.  
  548. do i = (from_out.COUNT-1) to 0 by -1
  549.  
  550.    if i < low_f then leave
  551.  
  552.    j = j + 1
  553.  
  554.    call writeln( 'temp', copies( ' ', length( j_f ) - length( j ) ) || j || '. ' || from_out.i )
  555. end
  556.  
  557. call writeln( 'temp', '' )
  558.  
  559.  
  560. j = 0
  561. call writeln( 'temp', toptext 'Recipiants:' )
  562. call writeln( 'temp', mline                 )
  563.  
  564. do i = (to_out.COUNT - 1 ) to 0 by -1
  565.  
  566.    if i < low_t then leave
  567.  
  568.    j = j + 1
  569.  
  570.    call writeln( 'temp', copies( ' ', length( j_t ) - length( j ) ) || j || '. ' || to_out.i )
  571.  
  572. end
  573.  
  574. call writeln( 'temp', '' )
  575.  
  576.  
  577. j = 0
  578. call writeln( 'temp', toptext 'Topics:' )
  579. call writeln( 'temp', mline             )
  580.  
  581. do i = (subj_out.COUNT - 1) to 0 by -1
  582.  
  583.    if i < low_s then leave
  584.  
  585.    j = j + 1
  586.    call writeln( 'temp', copies( ' ', length( j_s ) - length( j ) ) || j || '. ' || subj_out.i )
  587.  
  588. end
  589.  
  590. call writeln( 'temp', '' )
  591.  
  592. j = 0
  593.  
  594. call writeln( 'temp', toptext 'Quoters:' )
  595. call writeln( 'temp', mline             )
  596.  
  597. do i = (quoting_out.COUNT - 1) to 0 by -1
  598.  
  599.    if i < low_q then leave
  600.  
  601.    j = j + 1
  602.    call writeln( 'temp', copies( ' ', length( j_q ) - length( j ) ) || j || '. ' || quoting_out.i )
  603.  
  604. end
  605.  
  606. call writeln( 'temp', '' )
  607.  
  608. j = 0
  609.  
  610. if chars_out.COUNT>0 then do
  611.  
  612. call writeln( 'temp', toptext 'writers of off-policy characters:' )
  613. call writeln( 'temp', mline             )
  614.  
  615.  
  616. do i = (chars_out.COUNT - 1) to 0 by -1
  617.  
  618.    if i < low_o then leave
  619.  
  620.    j = j + 1
  621.    call writeln( 'temp', copies( ' ', length( j_o ) - length( j ) ) || j || '. ' || chars_out.i )
  622.  
  623. end
  624.  
  625. call writeln( 'temp', '' )
  626.  
  627. end
  628.  
  629. call close( 'temp' )
  630.  
  631. if output_file ~= '' then address command 'copy' temp_file '"'output_file'"'
  632.  
  633. if output_area ~= '' then
  634. do
  635.    MM_GetSysop sysop
  636.    sysop = sysop||'''s Statistics'
  637.    origine =  ' Mail Manager statistics of '||area.NAME
  638.    mess.FROM = sysop
  639.    mess.FROMADDR = area.ADDR
  640.    mess.TO = 'All'
  641.    mess.SUBJ = 'Stats for this area'
  642.    mess.TEAR = 'GG AreaStat'
  643.    mess.ORIGIN = origine
  644.  
  645.    if exists( temp_file ) then mess.FILE = temp_file
  646.  
  647.    MM_WriteMsg output_area 'mess'
  648.  
  649. end
  650.  
  651. address command 'Delete >NIL:' temp_file
  652.  
  653. ScriptEnd:
  654.  
  655. exit 0
  656.  
  657. error:
  658. syntax:
  659.  
  660. if rc>0 then error_text = errortext(rc)
  661.  
  662. say '** GG AreaStat: error at' rc sigl error_text
  663.  
  664. exit rc
  665.  
  666. Requester: PROCEDURE EXPOSE MM.
  667.  
  668. PARSE ARG Titolo, Testo, GadGets
  669. MM_Requester '"'Titolo'"' 'Testo' 'GadGets'
  670.  
  671. RETURN
  672.